/****************************************************************************
 * Copyright (c) 2014 - 2019 Qualcomm Technologies International, Ltd.
****************************************************************************/
#ifndef OP_MSG_UTILITIES_H
#define OP_MSG_UTILITIES_H

/************************* Public constants and macros ******************* */

/* Calculate size of statistics in 16-bit words:
 *    Packed 24-bit stats size = ceil(3*num_stats / 2)
 *    Packed 32-bit stats size = 2*num_stats
 */
#define CALC_STATS_SIZE(x)       ((sizeof(x)*2) >> LOG2_ADDR_PER_WORD)

/* Packing ratio of two (unsigned) int vars into 16-bit words:
 *    Packed 24-bit stats ratio is 3:2
 *    Packed 32-bit stats ratio is 4:2
 */
#define CPS_PACK_RATIO_NUM               4
#define CPS_PACK_RATIO_DENOM             2
#define CPS_PACK_RATIO           ((2*CPS_PACK_RATIO_NUM)/CPS_PACK_RATIO_DENOM)

/* State flags for persistent parameter loading */
#define PARAMETERS_READY                (1)
#define PARAMETERS_NOT_READY            (0)

/* Flag and masks used to check defaults flag in number of blocks field in set parameter message */
#define CPS_DEFAULT_PARAMETERS_FLAG     (0x8000)
#define CPS_DEFAULT_PARAMETERS_MASK     (~CPS_DEFAULT_PARAMETERS_FLAG)

/**
 * Parameter Access Common Data Object 
 */
typedef struct
{
   unsigned *default_ptr;		/* Address for default constant data */
   unsigned *param_ptr;			/* Pointer to Parameter RAM block */
   unsigned  num_params;		/* Number of Parameters in block*/
   unsigned  param_state;		/* Status of parameters */
   unsigned  ucid;				/* UCID for Parameter PsStore */
}CPS_PARAM_DEF;


/***************************** Public functions *************************** */

/*  These are common functions used to support parameters as generated by
 *   the CPS and accessed through the OBPM. TODO: Doxygenise them.
 */
extern void cps_mask16bit(unsigned *in_ptr,unsigned length);

extern unsigned* cpsPack2Words(unsigned val1, unsigned val2, unsigned *out_ptr);
extern unsigned* cpsPack1Word(unsigned val, unsigned *out_ptr);

extern unsigned cpsCheckParameterEncoding(unsigned num_blocks);

#endif // OP_MSG_UTILITIES_H
